package com.ljx.blog.article.controller;

import com.ljx.blog.article.domain.vo.req.ThemeSubmitReq;
import com.ljx.blog.article.domain.vo.resp.ThemeResp;
import com.ljx.blog.article.service.ThemeService;
import com.ljx.blog.common.domain.vo.resp.ApiResult;
import com.ljx.blog.security.annotation.ApiPermission;
import com.ljx.blog.security.common.PermissionConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-10-12  22:04
 */
@Api(tags = "主题接口")
@RestController
@RequestMapping("/theme")
public class ThemeController {

    @Autowired
    private ThemeService themeService;

    @ApiOperation("获取主题信息")
    @GetMapping("/info/{id}")
    public ApiResult<ThemeResp> getInfo(@PathVariable("id") Long themeId){
        return ApiResult.success(themeService.getInfo(themeId));
    }

    @ApiPermission(permissions = {PermissionConstant.THEME_NEW_EDIT, PermissionConstant.ADMIN_NEW_EDIT})
    @ApiOperation("保存/更新主题")
    @GetMapping("/submit")
    public ApiResult<ThemeResp> submit(@Validated @RequestBody ThemeSubmitReq req){
        return ApiResult.success(themeService.submit(req));
    }

    @ApiOperation("初始化主题信息")
    @GetMapping("/init")
    public ApiResult<List<ThemeResp>> init(){
        return ApiResult.success(themeService.init());
    }

    @ApiPermission(permissions = {PermissionConstant.THEME_NEW_EDIT, PermissionConstant.ADMIN_NEW_EDIT})
    @ApiOperation("批量更新主题")
    @PostMapping("/batch/submit")
    public ApiResult<List<ThemeResp>> batchSubmit(@RequestBody List<ThemeSubmitReq> req){
        return ApiResult.success(themeService.batchSubmit(req));
    }
}
